/**
 * 
 */
package anyware.desktop.dao.impl;

import java.util.Collection;

import org.apache.commons.lang.Validate;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import anyware.common.dao.support.HibernateGenericDaoSupport;
import anyware.desktop.dao.FileItemDao;
import anyware.desktop.model.FileItem;

/**
 * @author keke
 * 
 */
@Repository("fileItemDao")
public class HibernateFileItemDao extends
        HibernateGenericDaoSupport<FileItem, Long> implements
        FileItemDao<Criteria> {

    public HibernateFileItemDao() {
        super(FileItem.class);
    }

    public FileItem getByPath(final String path) {
        Validate.notNull(path);
        return findOnly(currentSession().createCriteria(clazz).add(
                Restrictions.eq("pathUrl", path)));
    }

    public Collection<FileItem> getDirtyItems() {
        return currentSession().createQuery(
                "from FileItem item where item.info.dirty=:dirty").setBoolean(
                "dirty", true).list();
    }
}
